<?php
	include "config.php";
	include "class/cart.php";
	include "class/konsumen.php";
	include "class/order.php";
	include "class/keranjang.php";
	
	$cart=new Cart();
	
	if(isset($_POST['command'])=='simpan'){
		$konsumen_dao=new Konsumen_Dao();
		$konsumen=new Konsumen();
		$konsumen->nama_pembeli=$_POST['nama_pembeli'];
		$konsumen->alamat_pembeli=$_POST['alamat_pembeli'];
		$konsumen->kodepos=$_POST['kodepos'];
		$konsumen->telepon=$_POST['telepon'];
		$konsumen->email_pembeli=$_POST['email_pembeli'];
		$konsumen->nama_bank_pembeli=$_POST['nama_bank_pembeli'];
		$konsumen->cabang_bank_pembeli=$_POST['cabang_bank_pembeli'];
		$konsumen->atas_nama=$_POST['atas_nama'];
		$konsumen->nomor_rekening=$_POST['nomor_rekening'];
		$konsumen_dao->add($konsumen);
		
		$order_dao=new Order_Dao();
		$order=new Order ();
		$order->id_konsumen=mysql_insert_id();
		$order->tanggal=date('Y-m-d');
		$order->total=$cart->get_order_total();
		$order->status="1";
		$order_dao->add($order);
		$x = mysql_insert_id();
		$max=count($_SESSION['cart']);
		for($i=0;$i<$max;$i++){
		$pid=$_SESSION['cart'][$i]['productid'];
		$q=$_SESSION['cart'][$i]['qty'];
		$keranjang_dao=new Keranjang_Dao();
		$keranjang=new Keranjang ();
		$keranjang->orderid=$x;
		echo $keranjang->orderid;
		$keranjang->id_oleh2=$pid;
		$keranjang->jumlah=$q;
		$keranjang_dao->add($keranjang);
		}
		die (header("location:?menu=berhasil"));
	}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Isi Biodata</title>
<link rel="stylesheet" href="css/val.css" type="text/css" />

  <script type="text/javascript" src="js/jquery-1.4.js"></script>
  <script type="text/javascript" src="js/jquery.validate.js"></script>
  <script type="text/javascript">
		$(document).ready(function() {
			$("#form1").validate({
				rules: {
				nama_pembeli: "required",
				alamat_pembeli: "required",
				kodepos: {
	          		required: true,
					number: true,
					minlength: 5
          		},
				telepon: {
	          		required: true,
					number: true
          		},
          		email_pembeli: {				
					required: true,
					email: true
				},
				nama_bank_pembeli: "required",
          		cabang_bank_pembeli: "required",
          		atas_nama: "required",
          		nomor_rekening: {
	          		required: true,
					number: true
          		},
				},
			
      	messages: { 
			    nama_pembeli: {
				    required: '. Nama harus di isi'
			    },
			    alamat_pembeli: {
				    required: '. Alamat harus di isi'
			    },
			    kodepos: {
				    required: '. Kode Pos harus di isi',
				    minlength: '. Kode Pos harus 5 Angka',
				    number  : '. Hanya boleh di isi Angka'
			    },
		      	telepon: {
				    required: '. No Telp / Hp harus di isi',
				    number  : '. Hanya boleh di isi Angka'
			    },
			    email_pembeli: {
				    required: '. Email harus di isi',
				    email   : '. Email harus valid'
			    },
			    nama_bank_pembeli: {
				    required: '. Nama Bank di isi'
			    },
			    cabang_bank_pembeli: {
				    required: '. Cabang Bank harus di isi'
			    },
			    atas_nama: {
				    required: '. Atas Nama harus di isi'
			    },
			    nomor_rekening: {
				    required: '. No Rekening harus di isi',
				    number  : '. Hanya boleh di isi Angka'
			    },
			   },
         
         success: function(label) {
            label.text('OK!').addClass('valid');
         }
			});
		});
	</script>
</head>
<body>
<div class="form-div">
<form id="form1" method=post onsubmit="return validate()">
<table width="95%" border="0" align="center">
    <input type="hidden" name="command" />
	<tr><td>Total Pembelian:</td><td>Rp.<?=$cart->get_order_total()?></td></tr>
	<br>
        <table border="0" cellpadding="2px">
	<br>
			<tr valign="top"> 
				  <td colspan="2"></td><td height="19"><font size="3" face="tahoma">Masukkan Data Anda </font></td>
				  </tr>	
			<tr valign="top"> 
				  <td width="21%" align="center"> <div align="left"><font size="2" face="tahoma">Nama</font></div></td>
				  <td width="1%">:</td>
				  <td width="78%" align="center"> <div align="left"> <font size="2" face="tahoma"> 
				  <input name="nama_pembeli" type="text" id="nama_pembeli" size="30" maxlength="50">
				  </font></div></td>
			</tr>
			<tr valign="top"> 
				  <td align="center"> <div align="left"><font size="2" face="tahoma">Alamat</font></div></td>
				  <td>:</td>
				  <td align="center"> <div align="left"> <font size="2" face="tahoma"> 
				  <textarea name="alamat_pembeli" cols="40" rows="4" id="alamat_pembeli"></textarea>
				  </font></div></td>
			</tr>
			<tr valign="top"> 
				  <td width="21%" align="center"> <div align="left"><font size="2" face="tahoma">Kode Pos</font></div></td>
				  <td width="1%">:</td>
				  <td width="78%" align="center"> <div align="left"> <font size="2" face="tahoma"> 
				  <input name="kodepos" type="text" id="kodepos" size="30" maxlength="5">
				  </font></div></td>
			</tr>
			<tr valign="top"> 
				  <td align="center"><div align="left"><font size="2" face="tahoma">Telp / Hp</font></div></td>
				  <td><div align="left">:</div></td>
				  <td align="center"><div align="left"><font size="2" face="tahoma"> 
				  <input name="telepon" type="text" id="telepon" maxlength="20">
				  </font></div></td>
			</tr>
			<tr valign="top"> 
				  <td align="center"> <div align="left"><font size="2" face="tahoma">E-Mail</font></div></td>
				  <td>:</td>
				  <td align="center"> <div align="left"> <font size="2" face="tahoma"> 
				  <input name="email_pembeli" type="text" id="email_pembeli" size="50" maxlength="50">
				   <br>
				  </font></div></td>
			</tr>
			<tr>
			<td colspan=2 align=center></td><td><font face=tahoma size=2><br><br>Informasi Rekening Anda</font></td>
			</tr>
			<tr valign="top"> 
				  <td width="21%" align="center"> <div align="left"><font size="2" face="tahoma">Nama Bank</font></div></td>
				  <td width="1%">:</td>
				  <td width="78%" align="center"> <div align="left"> <font size="2" face="tahoma"> 
				  <input name="nama_bank_pembeli" type="text" id="nama_bank_pembeli" size="30" maxlength="30">
				  </font></div></td>
			</tr>
			<tr valign="top"> 
				  <td width="21%" align="center"> <div align="left"><font size="2" face="tahoma">Cabang</font></div></td>
				  <td width="1%">:</td>
				  <td width="78%" align="center"> <div align="left"> <font size="2" face="tahoma"> 
				  <input name="cabang_bank_pembeli" type="text" id="cabang_bank_pembeli" size="30" maxlength="50">
				  </font></div></td>
			</tr>
			<tr valign="top"> 
				  <td width="21%" align="center"> <div align="left"><font size="2" face="tahoma">Atas Nama</font></div></td>
				  <td width="1%">:</td>
				  <td width="78%" align="center"> <div align="left"> <font size="2" face="tahoma"> 
				  <input name="atas_nama" type="text" id="atas_nama" size="30" maxlength="50">
                  </font></div></td>
			</tr>
			<tr valign="top"> 
				  <td align="center"><div align="left"><font size="2" face="tahoma">No. Rekening Bank</font></div></td>
				  <td><div align="left">:</div></td>
				  <td align="center"><div align="left"><font size="2" face="tahoma"> 
				  <input name="nomor_rekening" type="text" id="nomor_rekening" maxlength=20>
				  </font></div></td>
			</tr>
            <tr valign="top"> 
				  <td colspan="2"></td><td height="21">
				  <label>
				  <input type="submit" name="submit" value="Simpan">
				  </label></td>
			</tr>
    </table></div>
</form>
</body>
</html>
